package  com.songyl.patternLearn.ObserverPattern;

import java.util.ArrayList;
import java.util.List;

/**
 * 目标
 * 提供注册和删除观察者接口
 */
public class Registry {

    List<PlayerObserver> playerObserverList
            = new ArrayList<PlayerObserver>();

    /**
     * 注册观察者
     * @param playerObserver
     */
    public  void registryObserver(PlayerObserver playerObserver){
        playerObserverList.add(playerObserver);
    }

    /**
     * 删除观察者
     * @param playerObserver
     */
    public void removeObserver(PlayerObserver playerObserver){
        playerObserverList.remove(playerObserver);
    }

    /**
     * 发送给观察者消息
     */
    public void sendOBState(){
        for (PlayerObserver play:playerObserverList) {
            play.updateOBState();

        }
    }


}
